package com.gdth.bank.activity;

import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.gdth.bank.R;
import com.gdth.bank.adapter.ContactListAdapter;
import com.gdth.bank.bean.ContactBean;
import com.gdth.bank.presenter.ContactPresenter;
import com.gdth.bank.ui.QuickAlphabeticBar;
import com.gdth.bank.utils.AppUtil;
import com.gdth.bank.view.ContactView;
import com.gdth.core.annotation.view.ViewInject;
import com.gdth.core.widget.BaseActivity;
import com.gdth.widget.dialog.BaseToast;

public class TxlActivity extends BaseActivity implements ContactView{
	@ViewInject(id=R.id.header_label_title) TextView txt_header_title;
	@ViewInject(id=R.id.header_btn_left, click="finishClick") TextView txt_header_left;
    @ViewInject(id=R.id.header_btn_right) TextView txt_header_right;
    
    /****/
	@ViewInject(id=R.id.txl_list, itemClick="onItemClick") ListView contactList;
	/**快速索引条**/
	@ViewInject(id=R.id.fast_scroller) QuickAlphabeticBar alphabeticBar;
	ContactPresenter mContactPresenter;
	private ContactListAdapter adapter;
	private List<ContactBean> contactBeans;
	private String key;

    @Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_txl);
		
		initview();
    }
    
    private void initview(){
    	txt_header_right.setVisibility(View.GONE);
    	txt_header_title.setText(getResources().getString(R.string.param257));
    	Intent intent = this.getIntent();
    	key = intent.getStringExtra("key");
		mContactPresenter = new ContactPresenter(this);
		
		mContactPresenter.getContactList();
	}
	
	private void setAdapter(List<ContactBean> list) {
		adapter = new ContactListAdapter(this, list, alphabeticBar);
		contactList.setAdapter(adapter);
		alphabeticBar.init(this);
		alphabeticBar.setListView(contactList);
		alphabeticBar.setHight(alphabeticBar.getHeight());
		alphabeticBar.setVisibility(View.VISIBLE);
	}
	
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		ContactBean mContactBean = contactBeans.get(arg2);
		
		String number = mContactBean.getPhoneNum();
		showMessage(getResources().getString(R.string.param258) + number);
		
		Intent intent = new Intent();
		intent.putExtra("number", number);
		intent.putExtra("key", key);
		this.setResult(AppUtil.activity_txl_resultcode, intent);
		this.finish();
	}

	@Override
	public void updateContacts(List<ContactBean> contactList){
		// TODO Auto-generated method stub
		contactBeans = contactList;
		setAdapter(contactList);
	}

	@Override
	public void showProgressDialog() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void hideProgressDialog() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void showMessage(String msg) {
		// TODO Auto-generated method stub
		BaseToast.getInstance().ShowSystemToast(this, msg);
	}
}
